<%@ page import="com.wanghuadi.beans.Gender" %>
<%@ page import="com.wanghuadi.beans.Category" %>
<%@ page import="com.wanghuadi.beans.Subject" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<head>
    <title>Title</title>
    <link href="<%=request.getContextPath()%>/css/css.css" rel="stylesheet">
    <script src="<%=request.getContextPath()%>/js/jquery-1.8.2.min.js"></script>
    <script>
        $(function(){

            /*当页面加载时 查询学生信息回显  并获取动态下拉*/
            $.post("findByStudentById",{"id":"${param.id}"},function(data){
                var  student = data.student;
                var  typeList = data.typeList;
                /*var  genders = data.genders;
                var  categories = data.categories;
                var  subjects = data.subjects;
                */


               /* var Subject = Java.type("com.wanghuadi.beans.Subject")
                for(var i in subjects){
                    $("#category").append("<option value='"+subjects[i]+"'>"+subjects[i]+"</option>");
                    console.log(Subject.getName(subjects[i]))
                }*/

                $("[name='sno']").val(student.sno);
                $("[name='name']").val(student.name);
                $("[name='birthday']").val(student.birthday);
                $("[name='school']").val(student.school);

                //加分类型下拉
                for(var i in typeList){
                    $("#tid").append("<option value='"+typeList[i].id+"'>"+typeList[i].name+"</option>");
                }
                $("#tid").val(student.tid);


                $("#category").val(student.category);
                $("#subject").val(student.subject);
                $("[name='gender'][value='"+student.gender+"']").attr("checked",true);
            },"json")
        })
    </script>
    <script>
        function update(){
            $.post("updateStudent",$("form").serialize(),function(data){
                if(data){
                    alert("修改成功!");
                    location.href="list";
                }else{
                    alert("修改失败!");
                }

            })
        }
    </script>
</head>
<body>

    <form action="#">
        <input type="hidden" name="id" value="${param.id}">
        学生学号:<input type="text" name="sno"><br>
        学生姓名:<input type="text" name="name"><br>
        学生性别:<c:forEach items="<%=Gender.values()%>" var="g">
                    <input type="radio" name="gender" value="${g.name()}">${g.name}
                </c:forEach><br>
        出生日期:<input type="date" name="birthday"><br>
        类别:<select name="category" id="category">
                <c:forEach items="<%=Category.values()%>" var="g">
                    <option value="${g.name()}">${g.name}</option>
                </c:forEach>
        </select><br>
         学科:<select name="subject" id="subject">
                    <c:forEach items="<%=Subject.values()%>" var="s">
                        <option value="${s.name()}">${s.name}</option>
                    </c:forEach>
             </select><br>
        所在学校:<input type="text" name="school"><br>
        加分类型:<select  name="tid" id="tid">

                </select><br>
        <input type="button" value="保存" onclick="update()">
    </form>

</body>
</html>
